var _pInfo = {
	"userInfo": null,
	"firstText": {
		"#popup-titile": "新资金密码",
		"#popup-sub-title": "请输入新6位数资金密码",
		"#popup-ipt": "请输入新资金密码",
		"#popup-next": "下一步"
	},
	"againText": {
		"#popup-titile": "新资金密码",
		"#popup-sub-title": "请再次输入新6位数资金密码",
		"#popup-ipt": "请再次输入新资金密码",
		"#popup-next": "提交"
	},
	"firstPwd": "",
	"againPwd": "",
	"doSubmitData": function() {
		var _pwd = $("#popup-ipt").val().trim();
		this.againPwd = _pwd;
		if(isNull(_pwd)) {
			$.toast("请输入新资金密码", "text");
			return;
		}
		if(_pwd.length < 6) {
			$.toast("资金密码必须为6位数", "text");
			return;
		}
		if(isNaN(_pwd)) {
			$.toast("资金密码必须是纯数字", "text");
			return;
		}
		if(this.firstPwd != this.againPwd) {
			$.toast("两次密码输入不一致", "text");
			return;
		}
		var _data = {
			"userid": _pInfo.userInfo["id"]
		}
		_data["newsafetyPasswd"] = _pwd;
		var opts = {
			url: _url + "/money/user/upsafetypasswd",
			type: "post",
			load: true,
			data: _data,
			success: function(rs) {
				if(isReqSucceed(rs)) {
					$.alert("修改资金密码成功", function() {
						window.location.href = "personal-data.html";
					});
				}
			}
		}
		AjaxRequest(opts);
	},
	"doValidateOldPwd": function() {
		var _data = {
			"userid": _pInfo.userInfo.id
		}
		var safetyPasswd = $("#safetyPasswd").val().trim();
		if(isNull(safetyPasswd)) {
			$.toast("请输入原资金密码", "text");
			return;
		}
		_data["safetyPasswd"] = safetyPasswd;
		var opts = {
			url: _url + "/money/wallet/paypwdproving",
			type: "post",
			load: true,
			data: _data,
			success: function(rs) {
				if(isReqSucceed(rs)) {
					$("#new-pwd-popup").popup();
				}
			}
		}
		AjaxRequest(opts);
	},
	"doSavePassword": function(type) {
		var _pwd = $("#popup-ipt").val().trim();
		var _obj = this.againText;
		if(type == 1) { //next
			if(isNull(_pwd)) {
				$.toast("请输入新资金密码", "text");
				return;
			}
			if(_pwd.length < 6) {
				$.toast("资金密码必须为6位数", "text");
				return;
			}
			if(isNaN(_pwd)) {
				$.toast("资金密码必须是纯数字", "text");
				return;
			}
			_pInfo.firstPwd = _pwd;
			$("#popup-next").attr("onclick", "doSubmitData()"); //提交
			$("#popup-return").attr("onclick", "doSavePassword(2)");
		}
		if(type == 2) { //prev
			_obj = this.firstText;
			$("#popup-next").attr("onclick", "doSavePassword(1)");
			$("#popup-return").attr("onclick", "doSavePassword(3)");
		}
		if(type == 3) {
			_obj = this.firstText;
			$.closePopup("#new-pwd-popup");
			$("#popup-ipt").val("");
		}
		$.each(_obj, function(key, val) {
			if(key == "#popup-ipt") {
				$(key).attr("placeholder", val).val("");
				if(type == 2) {
					$(key).val(_pInfo.firstPwd);
				}
				return;
			}
			$(key).html(val);
		});
	},
	"loadEvents": function() {
		_pInfo.userInfo = _user.getUserInfo();
	},
	"load": function() {
		this.loadEvents();
	}
}
exposeGlobalMethods({
	"doValidateOldPwd": function() {
		_pInfo.doValidateOldPwd();
	},
	"doSavePassword": function(type) {
		_pInfo.doSavePassword(type);
	},
	"doSubmitData": function() {
		_pInfo.doSubmitData();
	}
});
$(function() {
	_pInfo.load();
});